package com.zhangchundi.hadoop.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;

/**
 * 使用FileSystem读取文件
 * <p>
 * author: 张春嫡[zhangchundi@qudian.com]
 * date: 16/11/1
 * since: 1.0
 */
public class FileSystemCat {

    public static void main(String[] args) {

        String uri = "hdfs://127.0.0.1:9000/zhangchundi/word.txt";

        InputStream in = null;
        Configuration conf = new Configuration();
        try {
            FileSystem fs = FileSystem.get(URI.create(uri), conf);
            in = fs.open(new Path(uri));
            IOUtils.copyBytes(in, System.out, 4096, false);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeStream(in);
        }


    }

}
